﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="SalesReport.aspx.cs" Inherits="HTComics.Web.Admin.SalesReport1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <link href="../Css/jquery-ui-1.8.18.custom.css" rel="stylesheet" type="text/css" />
    <script src="../Scripts/jquery-ui-1.8.18.custom.min.js" type="text/javascript"></script>

    <script type="text/javascript">
        $(document).ready(doOnLoad);

        function doOnLoad() {
            $("#btnReGen").button().click(function () { window.location = "ReportCriteria.aspx"; return false; });
            $("#btnAdminHome").button().click(function () { window.location = "Home.aspx"; return false; });

            if (totalRows == 0)
                $("#divReportDetails").html("No data found for the selected dates");
            else
                loadPage(PAGE_FIRST);            
        }
    </script>

    <script type="text/javascript">
        var PAGE_SIZE = <%=pageSize%>;
        var PAGE_FIRST = "+";
        var PAGE_PREV = "<";
        var PAGE_NEXT = ">";
        var PAGE_LAST = "-";

        var totalRows = <%=totalRows%>;
        var currPage = 0;
        var maxPages = Math.ceil(totalRows / PAGE_SIZE);

        function loadPage(newPage) {
            var sInd = -1;

            if (newPage == -1)
                return;

            switch (newPage) {
                case PAGE_FIRST:
                    newPage = 0;
                    break;

                case PAGE_PREV:
                    if (currPage == 0) return;
                    newPage = currPage-1;
                    break;

                case PAGE_NEXT:
                    if (currPage == (maxPages - 1)) return;
                    newPage = currPage+1;
                    break;

                case PAGE_LAST:
                    newPage = (maxPages - 1);
                    break;   
            }
            
            $('tr[tag*="details"]').css('display','none');

            currPage = newPage;
            for (var i = 0; i <= PAGE_SIZE - 1; i++) {
                index = (newPage * PAGE_SIZE) + i;

                if (sInd == -1) sInd = index;

                if (index == totalRows) 
                {
                    index--;
                    break;
                }

                $("#row" + index).css("display","");
            }   
            
            $("#spnPager").html("Page " + (currPage+1) + " of " + maxPages);
        }
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Heading" runat="server">
Sales Report
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server">
    <button id="btnReGen">Generate Another Report</button>
    <button id="btnAdminHome">Admin Home</button>
    <br /><br />

    <div class="section">
        <span class="header">
            Summary
        </span>

    <div class="content">
        <table cellpadding="0" cellspacing="0" class="reportSummary">
            <tr class="row">
                <td width="25%">Start Date</td>
                <td width="25%"><%=summary_StartDate%></td>

                <td width="25%">End Date</td>
                <td width="25%"><%=summary_EndDate%></td>
            </tr>

            <tr class="row">
                <td width="25%">Total Orders</td>
                <td width="25%"><%=string.Format("{0:D}",summary_TotalOrders)%></td>

                <td width="25%">Total Quantity</td>
                <td width="25%"><%=string.Format("{0:D}",summary_TotalQuantity)%></td>
            </tr>

            <tr class="row">
                <td width="25%">Total Cost Price</td>
                <td width="25%"><%=string.Format("{0:N}",summary_TotalCost)%></td>

                <td width="25%">Total Sales Price </td>
                <td width="25%"><%=string.Format("{0:N}",summary_TotalSales)%></td>
            </tr>
        </table>
    </div>
    </div>

    <br /><br />
    <div class="section">
        <span class="header">
            Details
        </span>

    <div class="content" id="divReportDetails">
        <table id='tblDetails' class='reportDetails' cellpading='0' cellspacing='0'>
            <thead>
            <tr>
                <td>Order Date</td>
                <td>Order Code</td>                
                <td>Issue</td>
                <td>Condition</td>
                <td>Quantity</td>
                <td>Custom Field 1</td>
                <td>Cost</td>
                <td>Sales</td>
                <td>Discount</td>
                <td>User</td>
            </tr>            
            </thead>

            <%=html%>

            <tr>            
                <td colspan='9' id='tdPager'>
                    &nbsp;<a href='#' onclick='javascript:loadPage(PAGE_FIRST)'>First</a>&nbsp;
                    &nbsp;<a href='#' onclick='javascript:loadPage(PAGE_PREV)'>Previous</a>&nbsp;
                    <span id='spnPager'></span>
                    &nbsp;<a href='#' onclick='javascript:loadPage(PAGE_NEXT)'>Next</a>&nbsp;
                    &nbsp;<a href='#' onclick='javascript:loadPage(PAGE_LAST)'>Last</a>&nbsp;
                </td>
            </tr>
        </table>       
    </div>
    </div>
</asp:Content>
